home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / DEBUG_LE.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  9.0 KB  |  256 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import sub_arctic.lib.semantic_lens;
  5. import sub_arctic.lib.nametag_sem_draw;
  6. import sub_arctic.input.click_tracking;
  7. import sub_arctic.input.event;
  8.  
  9. import java.awt.Point;
  10. import java.awt.Dimension;
  11. import java.awt.Rectangle;
  12.  
  13. /** 
  14.  * This class is a special subclass of top_level that provides support for 
  15.  * a semantic_lens object providing debugging information about the 
  16.  * interactors installed under it.  To support a semantic lens it does
  17.  * extra damage declarations similar to those done by semantic_lens_parent.<p>
  18.  *
  19.  * The lens is initially disabled (debugging turned off) and can be brought 
  20.  * up (and removed) by a mouse click with certain modifier keys held down 
  21.  * (this defaults to control-shift, but can be reset).  When debugging_mode
  22.  * is turned on this object works by forcing its last child to be a semantic 
  23.  * lens (the configure() for this object moves the lens to be last if it is 
  24.  * not already last).  The semantic lens does a debug output traversal that 
  25.  * displays information about each interactor that it is over.<p>
  26.  * 
  27.  * This top_level is typically used with a fake_top_level child to keep 
  28.  * subtrees from being disturbed by the addition of the lens as the last 
  29.  * child (this can wreck layout constraints).  This is done in 
  30.  * debug_interactor_applet, for example.<p>
  31.  *
  32.  * @see sub_arctic.lib.semantic_lens_parent
  33.  * @see sub_arctic.lib.semantic
  34.  * @see sub_arctic.lib.debug_interactor_applet
  35.  * @author Scott Hudson
  36.  */
  37. public class debug_lens_top_level extends top_level implements click_tracking
  38.   {
  39.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  40.  
  41.     /**
  42.      * Construct a debug_lens_top_level object with know x,y, width and height.
  43.      *
  44.      * @param int x_v the x coordinate of this interactor (should be zero 
  45.      *                unless you want this interactor to not cover all of its 
  46.      *                hosting AWT parent).
  47.      * @param int y_v the y coordinate of this interactor (should be zero 
  48.      *                unless you want this interactor to not cover all of its 
  49.      *                hosting AWT parent).
  50.      * @param int w_v the width of this top_level (this is also tied to the 
  51.      *                size of the AWT component).
  52.      * @param int h_v the height of this top_level (this is also tied to the 
  53.      *                size of the AWT component).
  54.      */
  55.     public debug_lens_top_level(int x_v, int y_v, int w_v, int h_v)
  56.       {
  57.     /* let super class to its work */
  58.         super(x_v,y_v,w_v,h_v);
  59.  
  60.     /* create lens object and arrange for us to hear about all mouse button
  61.      * presses */
  62.     setup_lens();
  63.     manager.click_tracker.add_to_focus(this,null,null);
  64.  
  65.     /* start out of debug mode */
  66.     _debugging = false;
  67.       }
  68.  
  69.      //had:
  70.      //* @exception general PROPAGATED
  71.  
  72.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  73.   
  74.     /**
  75.      * Construct a debug_lens_top_level and give it default values for x,y, 
  76.      * width and height. We assume that the system will fill in these values 
  77.      * later.
  78.      */
  79.     public debug_lens_top_level()
  80.       {
  81.         this(0,0,0,0);
  82.       }
  83.  
  84.      //had:
  85.      //* @exception general PROPAGATED
  86.  
  87.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  88.  
  89.     /** 
  90.      * Catch damage from children and expand it to include damage from
  91.      * our lens if it overlaps any of that damage.  We need to do this
  92.      * because drawing in a lens is not limited to the bound of the object
  93.      * that created it (but is limited to the lens).  
  94.      *
  95.      * @param Point     top_left top-left corner of child's damage area (in our 
  96.      *                           coordinate system)
  97.      * @param Dimension sz       size of the damage area.
  98.      */
  99.     public void damage_from_child(Point top_left, Dimension sz) 
  100.     {
  101.       Rectangle damage;
  102.  
  103.           /* let the super class to child damage itself */
  104.       super.damage_self(top_left, sz);
  105.  
  106.       /* if we are not debugging that's it */
  107.       if (!debugging()) return;
  108.  
  109.       /* expand damage to include our whole lens if it overlaps any of
  110.        * the damage from the child.   */
  111.       damage = new Rectangle(top_left, sz);
  112.       if (_debug_lens.bound().intersects(damage))
  113.         damage_self(_debug_lens.pos(), _debug_lens.size());
  114.     }
  115.  
  116.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  117.  
  118.     /** Are we currently showing the debug lens? */
  119.     protected boolean _debugging = false;
  120.  
  121.     /** Are we currently showing the debug lens? */
  122.     public boolean debugging() {return _debugging;}
  123.  
  124.     /** Programmatically turn debugging lens on or off */
  125.     public void set_debugging(boolean setting) 
  126.       {
  127.     /* only do something if this is a change */
  128.     if (setting != _debugging)
  129.       {
  130.         /* set the new value */
  131.         _debugging = setting;
  132.         
  133.         /* if we are going on, put the lens in, otherwise take it out */
  134.         if (setting) 
  135.           add_child(_debug_lens);
  136.         else
  137.           remove_child(_debug_lens);
  138.       }
  139.       }
  140.  
  141.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  142.  
  143.     /** 
  144.      * The debugging lens object.  When we are in debugging mode, this will
  145.      * be installed and maintained as our last child.  Otherwise, it is 
  146.      * unrooted, and just hangs here.
  147.      */
  148.     protected semantic_lens _debug_lens = null;
  149.  
  150.     /** Initialize the debug lens */
  151.     protected void setup_lens()
  152.       {
  153.     int lw, lh;
  154.  
  155.     /* figure out a size for the lens that fits, starting from 200, 200 */ 
  156.     lw = Math.min(200,w()-10); 
  157.     lh = Math.min(200,w()-10);
  158.     if (lw < 0) lw = 10;
  159.     if (lh < 0) lh = 10;
  160.  
  161.     /* build semantic lens object */
  162.     _debug_lens = new semantic_lens(10,10, lw, lh, new nametag_sem_draw(),
  163.                     false, "Interactor-Scope", null, 
  164.                     null, nametag_sem_draw.id);
  165.       }
  166.  
  167.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  168.  
  169.     /** Override configure to force our lens child to be last (when enabled) */
  170.     public void configure()
  171.       {
  172.     /* if we are debugging, force our lens to be the last child */
  173.     if (debugging())
  174.       {
  175.         if (_debug_lens.child_index() != num_children()-1){
  176.           _debug_lens.move_to_top();
  177.         }
  178.       }
  179.     
  180.     /* set super class to the rest */
  181.     super.configure();
  182.       }
  183.  
  184.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  185.  
  186.     /** 
  187.      * The set of modifier keys that must be down for a mouse button press
  188.      * to toggle debugging mode on/off.  This will be some combination of
  189.      * event.ALT_MASK, event.CTRL_MASK, event.META_MASK, and event.SHIFT_MASK
  190.      * ORed together.  This defaults to event.SHIFT_MASK | event.CTRL_MASK.
  191.      */
  192.     protected int _signal_modifiers = event.SHIFT_MASK | event.CTRL_MASK;
  193.  
  194.     /** 
  195.      * The set of modifier keys that must be down for a mouse button press
  196.      * to toggle debugging mode on/off.  This will be some combination of
  197.      * event.ALT_MASK, event.CTRL_MASK, event.META_MASK, and event.SHIFT_MASK
  198.      * ORed together.  This defaults to event.SHIFT_MASK | event.CTRL_MASK.
  199.      *
  200.      * @return int the modifiers required to toggle the lens.
  201.      */
  202.     public int signal_modifiers() {return _signal_modifiers;}
  203.  
  204.     /** 
  205.      * Change the set of modifier keys that must be down for a mouse button 
  206.      * press to toggle debugging mode on/off.  The new value must be some 
  207.      * combination of event.ALT_MASK, event.CTRL_MASK, event.META_MASK, and 
  208.      * event.SHIFT_MASK ORed together.  
  209.      *
  210.      * @param int msk the modifiers required to toggle the lens.
  211.      */
  212.     public void set_signal_modifiers(int msk) 
  213.       {_signal_modifiers = msk;}
  214.  
  215.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  216.  
  217.     /** 
  218.      * Listen for mouse button press input somewhere in the interface.  We are 
  219.      * only interested mouse down events in the case that all the required 
  220.      * modifier keys are held down (and that occured inside us, not somewhere
  221.      * else).  In that case we toggle debugging mode (but still do not 
  222.      * consume the event).
  223.      *
  224.      * @see sub_arctic.input.click_tracking
  225.      * @param event  evt       the click event we receive.
  226.      * @param Object user_info (ignored here).
  227.      */
  228.     public boolean track_click(event evt, Object user_info)
  229.       {
  230.     if (evt.root_interactor() == this &&
  231.         evt.id() == event.MOUSE_DOWN && 
  232.         (evt.modifiers() & signal_modifiers()) == signal_modifiers())
  233.       set_debugging(!debugging());
  234.  
  235.     return false;
  236.       }
  237.  
  238.     /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  239.   }
  240. /*=========================== COPYRIGHT NOTICE ===========================
  241.  
  242. This file is part of the subArctic user interface toolkit.
  243.  
  244. Copyright (c) 1996 Scott Hudson and Ian Smith
  245. All rights reserved.
  246.  
  247. The subArctic system is freely available for most uses under the terms
  248. and conditions described in 
  249.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  250. and appearing in full in the lib/interactor.java source file.
  251.  
  252. The current release and additional information about this software can be 
  253. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  254.  
  255. ========================================================================*/
  256.